﻿//==================================================================
// Copyright (C) 2011  BPM
// 作 者：朱云
// 日 期：2011/12/21
// 描 述：对其CrmTeachSumup操作
// 版 本：1.00
// 
// 修改历史纪录
// 版 本  修改时间      修改人            修改内容     
//    
//==================================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using HF.Framework.SqlDataContract;
using HF.Framework.DataClientDBAgent;

namespace HF.Business.Finance
{
    public class Userflow
    {
         private SqlDataItem sqlDataItem = new SqlDataItem();
        private string[] fieldList = { "ID", "Code", "OrderId", "ThodometerId", "PrelectDate", "IsBargain", "IsStandard", "IsValue",
                                         "JWXID", "IsGripe", "GripeExplain", "IsClass", "ClassExplain", "TeachPlace", "CustomerPromis",
                                         "TutorId", "DeptId", "Explain", "Adduser", "Addtime", "EXP1", "EXP2", "EXP3", "EXP4", "WorkflowId",
                                         "WorkflowInsId", "WorktaskId", "WorktaskInsId" };

        private string tableName = "CrmTeachSumup";
        private string keyField = "WorkflowInsId";
        private string sqlString = "";
        public string ID="";
        public string Code = "";
        public string OrderId="";
        public string ThodometerId="";
        public string PrelectDate = "";
        public string IsBargain = "";
        public string IsStandard = "";
        public string IsValue = "";
        public string JWXID = "";
        public string IsGripe = "";
        public string GripeExplain = "";
        public string IsClass = "";
        public string ClassExplain = "";
        public string TeachPlace = "";
        public string CustomerPromis = "";
        public string TutorId = "";
        public string DeptId = "";
        public string Explain = "";
        public string Adduser = "";
        public string Addtime = "";
        public string EXP1 = "";
        public string EXP2 = "";
        public string EXP3 = "";
        public string EXP4 = "";
        public string WorkflowId = "";
        public string WorkflowInsId = "";
        public string WorktaskId = "";
        public string WorktaskInsId = "";


        public Userflow()
        {
        }

        private void setParameter()
        {
            sqlDataItem.ParameterList.Clear(); ;
            sqlDataItem.AppendParameter("@ID", ID);
            sqlDataItem.AppendParameter("@Code", Code);
            sqlDataItem.AppendParameter("@OrderId", OrderId);
            sqlDataItem.AppendParameter("@ThodometerId", ThodometerId);
            sqlDataItem.AppendParameter("@PrelectDate", PrelectDate);
            sqlDataItem.AppendParameter("@IsBargain", IsBargain);
            sqlDataItem.AppendParameter("@IsStandard", IsStandard);
            sqlDataItem.AppendParameter("@IsValue", IsValue);
            sqlDataItem.AppendParameter("@JWXID", JWXID);
            sqlDataItem.AppendParameter("@IsGripe", IsGripe);
            sqlDataItem.AppendParameter("@GripeExplain", GripeExplain);
            sqlDataItem.AppendParameter("@IsClass", IsClass);
            sqlDataItem.AppendParameter("@ClassExplain", ClassExplain);
            sqlDataItem.AppendParameter("@TeachPlace", TeachPlace);
            sqlDataItem.AppendParameter("@CustomerPromis", CustomerPromis);
            sqlDataItem.AppendParameter("@TutorId", TutorId);
            sqlDataItem.AppendParameter("@DeptId", DeptId);
            sqlDataItem.AppendParameter("@Explain", Explain);
            sqlDataItem.AppendParameter("@Adduser", Adduser);
            sqlDataItem.AppendParameter("@Addtime", Addtime);
            sqlDataItem.AppendParameter("@EXP1", EXP1);
            sqlDataItem.AppendParameter("@EXP2", EXP2);
            sqlDataItem.AppendParameter("@EXP3", EXP3);
            sqlDataItem.AppendParameter("@EXP4", EXP4);
            sqlDataItem.AppendParameter("@WorkflowId", WorkflowId);
            sqlDataItem.AppendParameter("@WorkflowInsId", WorkflowInsId);
            sqlDataItem.AppendParameter("@WorktaskId", WorktaskId);
            sqlDataItem.AppendParameter("@WorktaskInsId", WorktaskInsId);

        }

        /// <summary>
        /// 获得CrmTeachSumup表
        /// </summary>
        /// <param name=WorkflowInsId></param>
        /// <returns></returns>
        public static DataTable GetCrmTeachSumupTable(string workflowInsId)
        {
            try
            {
                string sql = "select * from CrmTeachSumup where WorkflowInsId=@workflowInsId";
                SqlDataItem sqlItem = new SqlDataItem();
                sqlItem.CommandText = sql;
                sqlItem.AppendParameter("@workflowInsId", workflowInsId);
                ClientDBAgent agent = new ClientDBAgent();
                return agent.ExecuteDataTable(sqlItem);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void GetCrmTeachSumupInfo(string workflowinsid)
        {
            DataTable dt = GetCrmTeachSumupTable(workflowinsid);
            if (dt != null && dt.Rows.Count > 0)
            {
                ID = dt.Rows[0]["ID"].ToString();
                Code = dt.Rows[0]["Code"].ToString();
                OrderId=dt.Rows[0]["OrderId"].ToString();
                ThodometerId=dt.Rows[0]["ThodometerId"].ToString();
                PrelectDate=dt.Rows[0]["PrelectDate"].ToString();
                IsBargain=dt.Rows[0]["IsBargain"].ToString();
                IsStandard=dt.Rows[0]["IsStandard"].ToString();
                IsValue=dt.Rows[0]["IsValue"].ToString();
                JWXID=dt.Rows[0]["JWXID"].ToString();
                IsGripe=dt.Rows[0]["IsGripe"].ToString();
                GripeExplain=dt.Rows[0]["GripeExplain"].ToString();
                IsClass=dt.Rows[0]["IsClass"].ToString();
                ClassExplain=dt.Rows[0]["ClassExplain"].ToString();
                TeachPlace=dt.Rows[0]["TeachPlace"].ToString();
                CustomerPromis=dt.Rows[0]["CustomerPromis"].ToString();
                TutorId=dt.Rows[0]["TutorId"].ToString();
                DeptId=dt.Rows[0]["DeptId"].ToString();
                Explain = dt.Rows[0]["Explain"].ToString();
                Adduser=dt.Rows[0]["Adduser"].ToString();
                Addtime=dt.Rows[0]["Addtime"].ToString();
                EXP1=dt.Rows[0]["EXP1"].ToString();
                EXP2=dt.Rows[0]["EXP2"].ToString();
                EXP3=dt.Rows[0]["EXP3"].ToString();
                EXP4=dt.Rows[0]["EXP4"].ToString(); 
                WorkflowId = dt.Rows[0]["WorkflowId"].ToString();
                WorkflowInsId = dt.Rows[0]["WorkflowInsId"].ToString();
                WorktaskId = dt.Rows[0]["WorktaskId"].ToString();
                WorktaskInsId = dt.Rows[0]["WorktaskInsId"].ToString();

            }
        }
        private void setInsertSql()
        {
            string tmpValueList = "";
            string tmpFieldName = "";
            sqlString = "insert into " + tableName + "(";
            int tmpInt = this.fieldList.Length;
            for (int i = 0; i < tmpInt - 1; i++)
            {
                tmpFieldName = fieldList[i].ToString();
                sqlString = sqlString + tmpFieldName + ",";
                tmpValueList = tmpValueList + "@" + tmpFieldName + ",";
            }
            tmpFieldName = this.fieldList[tmpInt - 1].ToString();
            sqlString = sqlString + tmpFieldName;
            tmpValueList = tmpValueList + "@" + tmpFieldName;
            this.sqlString = sqlString + ")values(" + tmpValueList + ")";
            sqlDataItem.CommandText = sqlString;
        }
        private void setUpdateSql()
        {
            string tmpFieldName = "";
            int tmpInt = this.fieldList.Length;
            sqlString = "update " + tableName + " set ";
            for (int i = 0; i < tmpInt - 1; i++)
            {
                tmpFieldName = this.fieldList[i].ToString();
                sqlString = sqlString + tmpFieldName + "=@" + tmpFieldName + ",";
            }
            tmpFieldName = fieldList[tmpInt - 1].ToString();
            sqlString = sqlString + tmpFieldName + "=@" + tmpFieldName;
            sqlString = sqlString + " where " + keyField + "=@" + keyField;
            sqlDataItem.CommandText = sqlString;
        }
        /// <summary>
        /// 增加fin_Evection
        /// </summary>
        public void Insert()
        {
            try
            {
                setInsertSql();//设定insert语句
                setParameter();//设定参数
                ClientDBAgent agent = new ClientDBAgent();
                agent.ExecuteNonQuery(sqlDataItem);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 更新fin_Evection
        /// </summary>
        public void Update()
        {
            if (WorkflowInsId.Trim().Length == 0 || WorkflowInsId == null)
                throw new Exception("Update方法错误，WorkflowInsId不能为空！");
            try
            {
                setUpdateSql();//设定Update语句
                setParameter();//设定参数
                ClientDBAgent agent = new ClientDBAgent();
                agent.ExecuteNonQuery(sqlDataItem);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
